#pragma once

struct SSCROLLINFO
{
	UINT uiAllSize;	
	UINT uiPageSize;	
	UINT uiOffsetSize;

	SSCROLLINFO()
	{
		uiAllSize = 100;	
		uiPageSize = 100;	
		uiOffsetSize = 20;
	}
};
struct SScrollImg
{
	Image*	pImgNormal;
	Image*	pImgHover;
	Image*	pImgClick;
	Image*	pImgDisable;

	SScrollImg(){
		pImgDisable = NULL;
		pImgClick = NULL;
		pImgHover = NULL;
		pImgNormal = NULL;
	}
	~SScrollImg(){
		Release();
	}
	void Release(){
		if (pImgNormal){delete pImgNormal;  pImgNormal=NULL;}
		if (pImgHover){delete pImgHover;  pImgHover=NULL;}
		if (pImgClick){delete pImgClick;  pImgClick=NULL;}
		if (pImgDisable){delete pImgDisable;  pImgDisable=NULL;}
	}

};

// CComScrollBar
class CComScrollBar : public CWnd
{
	DECLARE_DYNAMIC(CComScrollBar)

public:
	CComScrollBar();
	virtual ~CComScrollBar();

protected:
	afx_msg void OnPaint();
    afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseHover(UINT nFlags, CPoint point);
	afx_msg void OnMouseLeave();

	afx_msg void OnBnClickBtnUp();
	afx_msg void OnBnClickBtnDown();
	DECLARE_MESSAGE_MAP()

public:
	static BOOL InitSkin(CString szFolder);
	static void	ReleaseSkin();

public:
	BOOL	Create( CWnd* pScrollCtrl, UINT nID, UINT nBarType = SB_VERT);
	BOOL	SetBarSize(UINT nSize);
	void	Layout();

	void	SetScrollPos( int pos, BOOL bInit = FALSE);
	UINT	GetScrollPos();
	BOOL	SetScrollInfo(SSCROLLINFO* si);
	void	GetScrollInfo(SSCROLLINFO* si);

private:
	void	_Draw(CDC* pDC);
	void	_DrawThunk(CDC *pDC);
	void	_DrawThumb( CDC *pDC);
	void	_DrawAllow(CDC* pDC);
    void    _DrawThumbBorderAndLine(CDC* pDC);
private:
    static Image*   m_pImgBk;
	static Image*	  m_pThunk;

	static SScrollImg m_thumbTop;
	static SScrollImg m_thumbCenter;
	static SScrollImg m_thumbBottom;
	static SScrollImg m_allowUp;
	static SScrollImg m_allowDown;
	static SScrollImg m_allowLeft;
	static SScrollImg m_allowRight;

	BOOL	m_bClickAllowUp;
	BOOL	m_bClickAllowDown;
	BOOL	m_bHoverAllowUp;
	BOOL	m_bHoverAllowDown;

	BOOL	m_bClickBar;
	BOOL	m_bHoverBar;
	BOOL	m_bClickTrunk;
	BOOL	m_bHoverTrunk;
	CPoint	m_ptLButtonDown;

private:
	CWnd*	m_pParent;			//滚动窗口控件和滚动条控件父窗口
	CWnd*	m_pScrollCtrl;		//滚动窗口控件
	int		m_nBarType;
	CSize	m_sizeScrollBar;	//垂直滚动条(X:宽度、Y：高度)   水平滚动条(X:高度、Y：宽度)
	CRect	m_rcThumb;
	CRect	m_rcTrunk;
	CRect	m_rcAllowUp;
	CRect	m_rcAllowDown;
    CRect   m_rcTopBorder;
    CRect   m_rcBottomBorder;
private:
	int		m_nScrollPos;		//滚动条处于位置
	int		m_nAllSize;			//总高度或总宽度
	int		m_nPageSize;		//页高度或页宽度
	int		m_nOffsetSize;		//每次滚动的大小

    CRect   m_rcThumbHorzLine;  //滚动条滑块的三条横线
    CRect   m_rcThumbBorder;    //滑块上下边界
    COLORREF m_clrSrcollBk;
    COLORREF    m_clrTBBorder;
};


